package com.baide.sanguanheyi.sqlite;


import com.baide.sanguanheyi.swing.MainContent;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @ClassName Content
 * @Description TODO
 * @Author wangbing
 * @Date 2020/5/19 8:52
 **/
@Table(name = "content")
@Entity
public class Content {
    @Id
    private String barCode;
    //重量
    private String weight;
    //有：0放行; 1查验（重量差异 海关拍_机器控制落此格口）; 2入库; 3放行征税; 4退运 ;5拒识（机器控制）;6-退单
    private String custOrder;
    //总包号
    private String voyageNo;
    //品名
    private String mainGName;
    //件数
    private String packNo;
    //CT返回状态
    private String ctOrder;
    //录入时间
    private Long time;
    //发件人名称
    private String SEND_NAME;
    //发件人地址
    private String SENDER_ADDR;
    //发件人电话
    private String SENDER_TEL;
    //收件人名称
    private String OWNER_NAME;
    //收件地址
    private String OWNER_ADDR;
    //收件人电话
    private String OWNER_TEL;
    @Transient
    private Map<String, Object> ct;
    @Transient
    private Map<String, String> luoDao;
    @Transient
    private int move;
    @Transient
    private long light2;
    @Transient
    private long light3;
    @Transient
    private List<Content> hindContents;


    public long getLight3() {
        return light3;
    }

    public void setLight3(long light3) {
        this.light3 = light3;
    }

    public List<Content> getHindContents() {
        return hindContents;
    }

    public void setHindContents(List<Content> hindContents) {
        this.hindContents = hindContents;
    }


    public long getLight2() {
        return light2;
    }

    public void setLight2(long light2) {
        this.light2 = light2;
    }

    public int getMove() {
        return move;
    }

    public int getYZMove() {
        if (custOrder == null)
            return 3;
        if ((ctOrder == null || ct == null) && barCode != null) {
            Map<String, Object> ctMap = MainContent.ctMap.get(barCode);
            if (ctMap != null) {
                ctOrder = ctMap.get("JudgeResult").toString();
                setCt(ctMap);
            }
//            else {
//                LoggerFactory.getLogger(Content.class).info("未获取到ct反馈,条码:" + barCode);
//            }
        }
        if (ctOrder == null) ctOrder = "C";
        if (!custOrder.equals("0")) {
            move = 2;
        } else if (ctOrder.equals("C")) {
            move = 1;
        } else {
            move = 2;
        }
        if (hindContents != null && hindContents.size() > 0) {
            for (Content c : hindContents) {
                if (c.getYZMove() != move) {
                    return 3;
                }
            }
        }
        return move == 0 ? 3 : move;
    }

    public void setMove(int move) {
        this.move = move;
    }

    public Map<String, Object> getCt() {
        return ct;
    }

    public void setCt(Map<String, Object> ct) {
        this.ct = ct;
    }

    public Map<String, String> getLuoDao() {
        return luoDao;
    }

    public void setLuoDao(Map<String, String> luoDao) {
        this.luoDao = luoDao;
    }

    public String getSEND_NAME() {
        return SEND_NAME;
    }

    public void setSEND_NAME(String SEND_NAME) {
        this.SEND_NAME = SEND_NAME;
    }

    public String getSENDER_ADDR() {
        return SENDER_ADDR;
    }

    public void setSENDER_ADDR(String SENDER_ADDR) {
        this.SENDER_ADDR = SENDER_ADDR;
    }

    public String getSENDER_TEL() {
        return SENDER_TEL;
    }

    public void setSENDER_TEL(String SENDER_TEL) {
        this.SENDER_TEL = SENDER_TEL;
    }

    public String getOWNER_NAME() {
        return OWNER_NAME;
    }

    public void setOWNER_NAME(String OWNER_NAME) {
        this.OWNER_NAME = OWNER_NAME;
    }

    public String getOWNER_ADDR() {
        return OWNER_ADDR;
    }

    public void setOWNER_ADDR(String OWNER_ADDR) {
        this.OWNER_ADDR = OWNER_ADDR;
    }

    public String getOWNER_TEL() {
        return OWNER_TEL;
    }

    public void setOWNER_TEL(String OWNER_TEL) {
        this.OWNER_TEL = OWNER_TEL;
    }

    public String getBarCode() {
        return barCode;
    }

    public void setBarCode(String barCode) {
        this.barCode = barCode;
    }

    public String getWeight() {
        return weight;
    }

    public void setWeight(String weight) {
        this.weight = weight;
    }

    public String getCustOrder() {
        return custOrder;
    }

    public void setCustOrder(String custOrder) {
        this.custOrder = custOrder;
    }

    public String getVoyageNo() {
        return voyageNo;
    }

    public void setVoyageNo(String voyageNo) {
        this.voyageNo = voyageNo;
    }

    public String getMainGName() {
        return mainGName;
    }

    public void setMainGName(String mainGName) {
        this.mainGName = mainGName;
    }

    public String getPackNo() {
        return packNo;
    }

    public void setPackNo(String packNo) {
        this.packNo = packNo;
    }

    public String getCtOrder() {
        return ctOrder;
    }

    public void setCtOrder(String ctOrder) {
        this.ctOrder = ctOrder;
    }

    public Long getTime() {
        return time;
    }

    public void setTime(Long time) {
        this.time = time;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Content content = (Content) o;
        return Objects.equals(barCode, content.barCode);
    }

    @Override
    public int hashCode() {
        return Objects.hash(barCode);
    }

    @Override
    public String toString() {
        return "Content{" +
                "barCode='" + barCode + '\'' +
                ", hindContents=" + hindContents +
                '}';
    }
}
